#include "GlobalHead.h"
#include "Workbench.h"
#include "Command.h"
#include "Gui_Application.h"
#include "CompleteApp.h"
#include "CompleteGui.h"

using namespace App;
using namespace Gui;
TYPESYSTEM_SOURCE_ABSTRACT(Workbench,Base::BaseClass)
Workbench::Workbench(void)
:_name("")
{
}

Workbench::~Workbench(void)
{
}

std::string Workbench::name()const
{
	return _name;
}
void Workbench::setName(const std::string& name)
{
	_name = name;
}

void Workbench::setupCustomToolbars(ToolBarItem* root,const char* toolbar)const
{
	std::string name = this->name();
	ParameterGrp::handle hGrp =GetApp_Application().GetUserParameter().GetGroup("BaseApp")
		->GetGroup("Workbench")->GetGroup(name.c_str())->GetGroup(toolbar);

	std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups();
	CommandManager& rMgr = Gui_Application::instance->commandManager();
	for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) {
		bool active = (*it)->GetBool("Active", true);
		if (!active) // ignore this toolbar
			continue;
		ToolBarItem* bar = new ToolBarItem(root);
		bar->setCommand("Custom");

		// get the elements of the subgroups
		std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup((*it)->GetGroupName())->GetASCIIMap();
		for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) {
			if (it2->first == "Separator") {
				*bar << "Separator";
			} else if (it2->first == "Name") {
				bar->setCommand(it2->second);
			} else {
				Command* pCmd = rMgr.getCommandByName(it2->first.c_str());
				if (!pCmd) { // unknown command
					// try to find out the appropriate module name
					std::string pyMod = it2->second + "Gui";
// 					try {
// 						Base::Interpreter().loadModule(pyMod.c_str());
// 					}
// 					catch(const Base::Exception&) {
// 					}
// 
// 					// Try again
// 					pCmd = rMgr.getCommandByName(it2->first.c_str());
				}

				if (pCmd) {
					*bar << it2->first; // command name
				}
			}
		}
	}
}
void Workbench::setupCustomShortcuts()const
{
	// Assigns user defined accelerators
// 	ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter();
// 	if ( hGrp->HasGroup("Shortcut") ) {
// 		hGrp = hGrp->GetGroup("Shortcut");
// 		// Get all user defined shortcuts
// 		const CommandManager& cCmdMgr = Gui_Application::instance->commandManager();
// 		std::vector<std::pair<std::string,std::string> > items = hGrp->GetASCIIMap();
// 		for ( std::vector<std::pair<std::string,std::string> >::iterator it = items.begin(); it != items.end(); ++it )
// 		{
// 			Command* cmd = cCmdMgr.getCommandByName(it->first.c_str());
// 			if (cmd && cmd->getAction())
// 			{
				// may be UTF-8 encoded
// 				QString str = QString::fromUtf8(it->second.c_str());
// 				QKeySequence shortcut = str;
// 				cmd->getAction()->setShortcut(shortcut);
// 			}
// 		}
// 	}
}
bool Workbench::activate()
{

 ToolBarItem* tb  = setupToolBars();
 setupCustomToolbars(tb,"toolbar");
 ToolBarManager::getIntances()->setup(tb);
 delete tb;

 ToolBarItem* cb = setupCommandBars();
 setupCustomToolbars(cb,"Toolboxbar");
 delete cb;

 DockWindowItems* dw = setupDockWindow();
 DockWindowManager::instance()->setup(dw);
 delete dw;

 MenuItem* mb = setupMenuBar();
 MenuManager::getInstance()->setup(mb);
 delete mb;

 setupCustomShortcuts();

  return true;
}

void Workbench::retranslate()const
{
	ToolBarManager::getIntances()->retranslate();
	DockWindowManager::instance()->retranslate();
	MenuManager::getInstance()->retranslate();
}

TYPESYSTEM_SOURCE(StdWorkbench,Workbench)

StdWorkbench::StdWorkbench()
:Workbench()
{

};

StdWorkbench::~StdWorkbench()
{

}

void StdWorkbench::setupContextMenu(const char* recipient,MenuItem*item)const
{ 
	if (strcmp(recipient,"View") == 0)
	{
		MenuItem* StdViews = new MenuItem;
		StdViews->setCommand( "Standard views" );

		*StdViews << "Std_ViewAxo" << "Separator" << "Std_ViewFront" << "Std_ViewTop" << "Std_ViewRight"
			<< "Std_ViewRear" << "Std_ViewBottom" << "Std_ViewLeft";

		*item << "Std_ViewFitAll" << "Std_ViewFitSelection" << StdViews
			<< "Separator" << "Std_ViewDockUndockFullscreen";

// 		if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0 )
// 			*item << "Separator" << "Std_SetAppearance" << "Std_ToggleVisibility" << "Std_TreeSelection" 
// 			<< "Std_RandomColor" << "Separator" << "Std_Delete";
	}
// 	else if (strcmp(recipient,"Tree") == 0)
// 	{
// 		if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0 )
// 			*item << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection"
// 			<< "Separator" << "Std_SetAppearance" << "Std_RandomColor"
// 			<< "Separator" << "Std_Delete";
// 	}
}
void StdWorkbench::createMainWindowPopupMenu(MenuItem* item)const
{
   *item << "Std_DlgCustomize";
}

MenuItem* StdWorkbench::setupMenuBar()const
{
	MenuItem* menuBar = new MenuItem;

	// File
	MenuItem* file = new MenuItem( menuBar );
	file->setCommand("&File");
	*file << "Std_New" << "Std_Open" << "Separator" << "Std_CloseActiveWindow"
		<< "Std_CloseAllWindows" << "Separator" << "Std_Save" << "Std_SaveAs"
		<< "Separator" << "Std_Import" << "Std_DWGImport" << "Std_TopoImport" <<"Std_Export" 
		<< "Std_MergeProjects" << "Std_ProjectInfo" 
		<< "Separator" << "Std_Print" << "Std_PrintPdf"
		<< "Separator" << "Std_RecentFiles" << "Separator" << "Std_Quit";

	// Edit
	MenuItem* edit = new MenuItem( menuBar );
	edit->setCommand("&Edit");
	*edit << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Cut" << "Std_Copy"
		<< "Std_Paste" << "Std_DuplicateSelection" << "Separator"
		<< "Std_Refresh" << "Std_SelectAll" << "Std_Delete" << "Std_Placement"
		<< "Separator" << "Std_DlgPreferences";

	// Standard views
	MenuItem* stdviews = new MenuItem;
	stdviews->setCommand("Standard views");
	*stdviews << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewAxo"
		<< "Separator" << "Std_ViewFront" << "Std_ViewRight"
		<< "Std_ViewTop" << "Separator" << "Std_ViewRear" 
		<< "Std_ViewLeft" << "Std_ViewBottom";

	// stereo
	MenuItem* view3d = new MenuItem;
	view3d->setCommand("&Stereo");
	*view3d << "Std_ViewIvStereoRedGreen" << "Std_ViewIvStereoQuadBuff" 
		<< "Std_ViewIvStereoInterleavedRows" << "Std_ViewIvStereoInterleavedColumns" 
		<< "Std_ViewIvStereoOff" << "Separator" << "Std_ViewIvIssueCamPos";

	// zoom
	MenuItem* zoom = new MenuItem;
	zoom->setCommand("&Zoom");
	*zoom << "Std_ViewZoomIn" << "Std_ViewZoomOut" << "Separator" << "Std_ViewBoxZoom";

	// Visibility
	MenuItem* visu = new MenuItem;
	visu->setCommand("Visibility");
	*visu << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection"
		<< "Separator" << "Std_ToggleObjects" << "Std_ShowObjects" << "Std_HideObjects" 
		<< "Separator" << "Std_ToggleSelectability";

	// View
	MenuItem* view = new MenuItem( menuBar );
	view->setCommand("&View");
	*view << "Std_ViewCreate" << "Std_OrthographicCamera" << "Std_PerspectiveCamera" << "Separator" 
		<< stdviews << "Std_FreezeViews" << "Separator" << view3d << zoom
		<< "Std_ViewDockUndockFullscreen" << "Std_ToggleClipPlane"
		<< "Std_TextureMapping" << "Separator" << visu
		<< "Std_ToggleVisibility" << "Std_ToggleNavigation"
		<< "Std_SetAppearance" << "Std_RandomColor" << "Separator" 
		<< "Std_MeasureDistance" << "Separator" 
		<< "Std_Workbench" << "Std_ToolBarMenu" << "Std_DockViewMenu" << "Separator" 
		<< "Std_ViewStatusBar";

	// Tools
// 	MenuItem* tool = new MenuItem( menuBar );
// 	tool->setCommand("&Tools");
// 	*tool << "Std_DlgParameter" << "Separator"
// 		<< "Std_ViewScreenShot" << "Std_SceneInspector" << "Std_DemoMode" 
// 		<< "Separator" << "Std_DlgCustomize";

	// Macro
// 	MenuItem* macro = new MenuItem( menuBar );
// 	macro->setCommand("&Macro");
// 	*macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute"
// 		<< "Separator" << "Std_DlgMacroExecuteDirect" << "Std_MacroStartDebug"
// 		<< "Std_MacroStopDebug" << "Std_MacroStepOver" << "Std_ToggleBreakpoint";

	// Windows
	MenuItem* wnd = new MenuItem( menuBar );
	wnd->setCommand("&Windows");
	*wnd << "Std_ActivateNextWindow" << "Std_ActivatePrevWindow" << "Separator"
		<< "Std_TileWindows" << "Std_CascadeWindows"
		<< "Std_ArrangeIcons" << "Separator" << "Std_WindowsMenu" << "Std_Windows";

	// Separator
	MenuItem* sep = new MenuItem( menuBar );
	sep->setCommand( "Separator" );

	// Help
	MenuItem* helpWebsites = new MenuItem;
	helpWebsites->setCommand("&On-line help");
	*helpWebsites << "Std_OnlineHelpWebsite" << "Std_FreeCADWebsite" << "Std_PythonWebsite";

	MenuItem* help = new MenuItem( menuBar );
	help->setCommand("&Help");
	*help << "Std_OnlineHelp" << "Std_OnlineHelpPython" << "Std_PythonHelp"
		<< helpWebsites  << "Std_TipOfTheDay"<< "Separator" << "Std_About"
		<< "Std_AboutQt" << "Separator" << "Std_WhatsThis";

	return menuBar;
}

ToolBarItem* StdWorkbench::setupToolBars()const
{
	ToolBarItem* root = new ToolBarItem;

	// File
	ToolBarItem* file = new ToolBarItem( root );
	file->setCommand("File");
	*file << "Std_New" << "Std_Open" << "Std_Save" << "Std_Print" << "Separator" << "Std_Cut"
		<< "Std_Copy" << "Std_Paste" << "Separator" << "Std_Undo" << "Std_Redo" << "Separator"
		<< "Std_Refresh" << "Separator"<< "Std_Workbench"<< "Std_WhatsThis";
//  <
	// Macro
// 	ToolBarItem* macro = new ToolBarItem( root );
// 	macro->setCommand("Macro");
// 	*macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute"
// 		<< "Std_DlgMacroExecuteDirect";

	// View
// 	ToolBarItem* view = new ToolBarItem( root );
// 	view->setCommand("View");
// 	*view << "Std_ViewFitAll" << "Separator" << "Std_ViewAxo" << "Separator" << "Std_ViewFront" 
// 		<< "Std_ViewRight" << "Std_ViewTop" << "Separator" << "Std_ViewRear" << "Std_ViewLeft" 
// 		<< "Std_ViewBottom" << "Separator" << "Std_MeasureDistance" ;

	return root;
} 

ToolBarItem* StdWorkbench::setupCommandBars()const
{
	ToolBarItem* root = new ToolBarItem;

	// View
	ToolBarItem* view = new ToolBarItem( root );
	view->setCommand("Standard views");
	*view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewAxo" << "Separator"
		<< "Std_ViewFront" << "Std_ViewRight" << "Std_ViewTop" << "Separator"
		<< "Std_ViewRear" << "Std_ViewLeft" << "Std_ViewBottom";
	// Special Ops
	ToolBarItem* macro = new ToolBarItem( root );
	macro->setCommand("Special Ops");
	*macro << "Std_DlgParameter" << "Std_DlgPreferences" << "Std_DlgMacroRecord" << "Std_MacroStopRecord" 
		<< "Std_DlgMacroExecute" << "Std_DlgCustomize";

	return root;
}

DockWindowItems* StdWorkbench::setupDockWindow()const
{
	DockWindowItems* root = new DockWindowItems();
	root->addDockWidget("Std_ToolBox", Qt::RightDockWidgetArea, false, false);
	//root->addDockWidget("Std_HelpView", Qt::RightDockWidgetArea, true, false);
	root->addDockWidget("Std_TreeView", Qt::LeftDockWidgetArea, true, false);
	root->addDockWidget("Std_PropertyView", Qt::LeftDockWidgetArea, true, false);
	root->addDockWidget("Std_SelectionView", Qt::LeftDockWidgetArea, false, false);
	root->addDockWidget("Std_CombiView", Qt::LeftDockWidgetArea, false, false);
	root->addDockWidget("Std_ReportView", Qt::BottomDockWidgetArea, true, true);
	//root->addDockWidget("Std_TaskPanelView", Qt::RightDockWidgetArea, false, false);
	root->addDockWidget("Std_PythonView", Qt::BottomDockWidgetArea, true, true);
	return root;
}
TYPESYSTEM_SOURCE(BlankWorkBench,Workbench)
BlankWorkBench::BlankWorkBench()
:Workbench()
{

}
BlankWorkBench::~BlankWorkBench()
{

}

MenuItem* BlankWorkBench::setupMenuBar()const
{
    return NULL;
}
ToolBarItem* BlankWorkBench::setupToolBars()const
{
   return NULL;
}
ToolBarItem* BlankWorkBench::setupCommandBars()const
{
    return NULL;
}

DockWindowItems* BlankWorkBench::setupDockWindow()const
{
    return NULL;
}

void BlankWorkBench::activated()
{

}
void BlankWorkBench::deactivated()
{

}

void BlankWorkBench::setupContextMenu(const char* recipient,MenuItem*item)const
{

}


TYPESYSTEM_SOURCE(NoneWorkbench,StdWorkbench)
NoneWorkbench::NoneWorkbench()
:StdWorkbench()
{

}

NoneWorkbench::~NoneWorkbench()
{

}

MenuItem* NoneWorkbench::setupMenuBar()const
{
	return StdWorkbench::setupMenuBar();

// 	MenuItem* menuBar = new MenuItem;
// 
// 	MenuItem* file = new MenuItem(menuBar);
// 	file->setCommand("&File");
// 	*file<<"Std_Quit";
// 
// 	MenuItem* edit = new MenuItem(menuBar);
// 	edit->setCommand("&Edit");
// 	*edit<<"Std_DlgPreferences";
// 
// 	MenuItem* view = new MenuItem(menuBar);
// 	view->setCommand("&View");
// 	*view<<"Std_Workbench"<<"Std_FreezeViews";
// 
// 
// 	MenuItem* sep = new MenuItem(menuBar);
// 	sep->setCommand("Separator");
// 
// 	MenuItem* help = new MenuItem(menuBar);
// 	help->setCommand("&Help");
// 	*help << "Std_OnlineHelp" <<"Std_About" <<"Std_AboutQt";
// 
//     return menuBar;
}
void NoneWorkbench::setupContextMenu(const char* recipient,MenuItem* item)const
{

}
ToolBarItem* NoneWorkbench::setupToolBars()const
{  
	ToolBarItem* root = StdWorkbench::setupToolBars();

// 	ToolBarItem* solids = new ToolBarItem(root);
// 	solids->setCommand("Solids");
// 	*solids << "Part_Box" << "Part_Cylinder" << "Part_Sphere" << "Part_Cone"
// 		<< "Part_Torus" << "Part_Primitives" << "Part_Builder";
// 
// 	ToolBarItem* tool = new ToolBarItem(root);
// 	tool->setCommand("Part tools");
// 	*tool << "Part_Extrude" << "Part_Revolve" << "Part_Mirror" << "Part_Fillet"
// 		<< "Part_Chamfer" << "Part_RuledSurface" << "Part_Loft" << "Part_Sweep";
// 
// 	ToolBarItem* boolop = new ToolBarItem(root);
// 	boolop->setCommand("Boolean");
// 	*boolop << "Part_Boolean" << "Part_Cut" << "Part_Fuse" << "Part_Common"
// 		<< "Part_Section" << "Part_CrossSections";

	return root;
}
ToolBarItem* NoneWorkbench::setupCommandBars()const
{
   ToolBarItem* root = new ToolBarItem;
    return root;
}

DockWindowItems* NoneWorkbench::setupDockWindow()const
{
	DockWindowItems* root = new DockWindowItems();
	root->addDockWidget("Std_ReportView", Qt::BottomDockWidgetArea, true, false);
	// root->addDockWidget("Std_CombiView", Qt::LeftDockWidgetArea, false, false);
   return root;
}

TYPESYSTEM_SOURCE(CompleteWorkbench,Workbench)

CompleteWorkbench::CompleteWorkbench()
{
}
CompleteWorkbench::~CompleteWorkbench()
{
	CompleteApp::destruct();
	CompleteGui::destruct();
}

void CompleteWorkbench::Initialize()
{	
// 	CompleteGui::Instatnce()->initCompleteGui();
// 	CompleteApp::Instance()->InitCompleteApp();

	//Gui_Application::instance->AddWorkbench(name());

}

MenuItem* CompleteWorkbench::setupMenuBar() const
{

	CommandManager &mgr = Gui_Application::instance->commandManager();
	// Setup the default menu bar
	MenuItem* menuBar = new MenuItem;

	// File
	MenuItem* file = new MenuItem( menuBar );
	file->setCommand("&File");
	*file << "Std_New" << "Std_Open" << "Separator" << "Std_CloseActiveWindow"
		<< "Std_CloseAllWindows" << "Separator" << "Std_Save" << "Std_SaveAs"
		<< "Separator" << "Std_Import" << "Std_Export"
		<< "Std_MergeProjects" << "Std_ProjectInfo" 
		<< "Separator" << "Std_Print" << "Std_PrintPdf"
		<< "Separator" << "Std_RecentFiles" << "Separator" << "Std_Quit";

	// Edit
	MenuItem* edit = new MenuItem( menuBar );
	edit->setCommand("&Edit");
	*edit << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Cut" << "Std_Copy"
		<< "Std_Paste" << "Std_DuplicateSelection" << "Separator"
		<< "Std_Refresh" << "Std_SelectAll" << "Std_Delete" << "Std_Placement"
		<< "Separator" << "Std_DlgPreferences";

	// Standard views
	MenuItem* stdviews = new MenuItem;
	stdviews->setCommand("Standard views");
	*stdviews << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewAxo"
		<< "Separator" << "Std_ViewFront" << "Std_ViewRight"
		<< "Std_ViewTop" << "Separator" << "Std_ViewRear" 
		<< "Std_ViewLeft" << "Std_ViewBottom";

	// stereo
	MenuItem* view3d = new MenuItem;
	view3d->setCommand("&Stereo");
	*view3d << "Std_ViewIvStereoRedGreen" << "Std_ViewIvStereoQuadBuff" 
		<< "Std_ViewIvStereoInterleavedRows" << "Std_ViewIvStereoInterleavedColumns" 
		<< "Std_ViewIvStereoOff" << "Separator" << "Std_ViewIvIssueCamPos";

	// zoom
    MenuItem* zoom = new MenuItem;
	zoom->setCommand("&Zoom");
	*zoom << "Std_ViewZoomIn" << "Std_ViewZoomOut" << "Separator" << "Std_ViewBoxZoom";

	// Visibility
	MenuItem* visu = new MenuItem;
	visu->setCommand("Visibility");
	*visu << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection"
		<< "Separator" << "Std_ToggleObjects" << "Std_ShowObjects" << "Std_HideObjects"
		<< "Separator" << "Std_ToggleSelectability";

	// View
	MenuItem* view = new MenuItem( menuBar );
	view->setCommand("&View");
	*view << "Std_ViewCreate" << "Std_OrthographicCamera" << "Std_PerspectiveCamera" << "Separator" 
		<< stdviews << "Std_FreezeViews" << "Separator" << view3d << zoom
		<< "Std_ViewDockUndockFullscreen" << "Std_ToggleClipPlane"
		<< "Std_TextureMapping" << "Separator" << visu
		<< "Std_ToggleVisibility" << "Std_ToggleNavigation"
		<< "Std_SetAppearance" << "Std_RandomColor" << "Separator" 
		<< "Std_MeasureDistance" << "Separator" 
		<< "Std_Workbench" << "Std_ToolBarMenu" << "Std_DockViewMenu" << "Separator" 
		<< "Std_ViewStatusBar";

	// Tools
	MenuItem* tool = new MenuItem( menuBar );
	tool->setCommand("&Tools");
	*tool << "Std_DlgParameter" << "Separator"
		<< "Std_DlgMacroRecord" << "Std_MacroStopRecord"
		<< "Std_DlgMacroExecute" << "Std_DlgMacroExecuteDirect" 
		<< "Separator"// << "Std_ViewScreenShot" << "Std_SceneInspector"
		<< "Std_DemoMode" << "Separator" << "Std_DlgCustomize";

	// Mesh ****************************************************************************************************
	MenuItem* mesh = new MenuItem( menuBar );

	// submenu analyze
	MenuItem* analyze = new MenuItem();
	analyze->setCommand("Analyze");
	*analyze << "Mesh_Evaluation" 
		<< "Mesh_EvaluateFacet" 
		<< "Mesh_CurvatureInfo" 
		<< "Separator" 
		<< "Mesh_EvaluateSolid" 
		<< "Mesh_BoundingBox";

	// submenu boolean
	MenuItem* boolean = new MenuItem();
	boolean->setCommand("Boolean");
	*boolean << "Mesh_Union" 
		<< "Mesh_Intersection" 
		<< "Mesh_Difference";

	mesh->setCommand("&Meshes");
	*mesh << "Mesh_Import" 
		<< "Mesh_Export" 
		<< "Mesh_FromGeometry" 
		<< "MeshPart_Mesher"
		<< "Separator"
		<< analyze 
		<< "Mesh_HarmonizeNormals" 
		<< "Mesh_FlipNormals" 
		<< "Separator" 
		<< "Mesh_FillupHoles" 
		<< "Mesh_FillInteractiveHole" 
		<< "Mesh_RemoveComponents"
		<< "Mesh_RemoveCompByHand"
		<< "Mesh_AddFacet"
		<< "Mesh_Smoothing"
		<< "Separator" 
		<< "Mesh_BuildRegularSolid" 
		<< boolean << "Separator" 
		<< "Mesh_PolySelect"
		<< "Mesh_PolyCut"
		<< "Mesh_PolySplit" 
		<< "Mesh_PolySegm" 
		<< "Mesh_ToolMesh" 
		<< "Mesh_VertexCurvature";

	// Part ****************************************************************************************************

	MenuItem* part = new MenuItem(menuBar);
	part->setCommand("&Part");

	// submenu boolean
	MenuItem* para = new MenuItem();
	para->setCommand("Parametric");
	*para << "Part_Box"
		<< "Part_Cylinder"
		<< "Part_Sphere"
		<< "Part_Cone"
		<< "Part_Torus"
		<< "Part_Primitives";
	*part << para
		<< "Part_ShapeFromMesh"
		<< "Part_MakeSolid"
		<< "Part_ReverseShape"
		<< "Separator"
		<< "Part_Boolean"
		<< "Part_Extrude"
		<< "Part_Revolve"
		<< "Part_Mirror"
		<< "Part_Fillet"
		<< "PartDesign_Chamfer"
		<< "Separator"
		<< "Part_ShapeInfo";


	// Drawing ****************************************************************************************************

	MenuItem* drawing = new MenuItem(menuBar);

	drawing->setCommand("&Drawing");
	*drawing
		<< "Drawing_Open" 
		<< "Separator" 
		<< "Drawing_NewA3Landscape"  
		<< "Drawing_NewView" 
		<< "Drawing_ExportPage"
		;

	// Raytracing ****************************************************************************************************

	MenuItem* raytracing = new MenuItem(menuBar);

	raytracing->setCommand("&Raytracing");
	*raytracing 
		<< "Raytracing_WriteView" 
		<< "Raytracing_WriteCamera" 
		<< "Raytracing_WritePart"; 
	;

	// Drafting ****************************************************************************************************
//#   ifdef COMPLETE_USE_DRAFTING
	//if (mgr.getCommandByName("Draft_Line")) {
		MenuItem* Drafting = new MenuItem(menuBar);
		Drafting->setCommand("&Drafting");

		MenuItem* DraftContext = new MenuItem();
		DraftContext->setCommand("Object appearence");

		*DraftContext << "Draft_ApplyStyle" << "Draft_ToggleDisplayMode";

		MenuItem* DraftWireTools = new MenuItem();
		DraftWireTools->setCommand("Wire Tools");

		*DraftWireTools << "Draft_WireToBSpline" << "Draft_AddPoint" << "Draft_DelPoint";

		*Drafting 
			<< "Draft_Line"
			<< "Draft_Wire"
			<< "Draft_Circle"
			<< "Draft_Arc"
			<< "Draft_Rectangle"
			<< "Draft_Polygon"
			<< "Draft_BSpline"
			<< "Draft_Text"
			<< "Draft_Dimension"
			<< "Separator" 
			<< "Draft_Move" 
			<< "Draft_Rotate" 
			<< "Draft_Offset" 
			<< "Draft_Trimex" 
			<< "Draft_Upgrade" 
			<< "Draft_Downgrade" 
			<< "Draft_Scale"
			<< "Draft_Edit"
			<< "Draft_Drawing"
			<< "DraftWireTools"
			<< "DraftContext";
//	}
//#   endif

	// xxx ****************************************************************************************************


	// Windows
	MenuItem* wnd = new MenuItem( menuBar );
	wnd->setCommand("&Windows");
	*wnd << "Std_ActivateNextWindow" << "Std_ActivatePrevWindow" << "Separator"
		<< "Std_TileWindows" << "Std_CascadeWindows"
		<< "Std_ArrangeIcons" << "Separator" << "Std_WindowsMenu" << "Std_Windows";

	// help ****************************************************************************************************
	// Separator
	MenuItem* sep = new MenuItem( menuBar );
	sep->setCommand( "Separator" );

	// Help
	MenuItem* helpWebsites = new MenuItem;
	helpWebsites->setCommand("&Online-help");
	*helpWebsites << "Std_OnlineHelpWebsite" 
		<< "Std_FreeCADWebsite" 
		<< "Std_PythonWebsite";

	MenuItem* help = new MenuItem( menuBar );
	help->setCommand("&Help");
	*help << "Std_OnlineHelp" 
		<< "Std_OnlineHelpPython" 
		<< "Std_PythonHelp"
		<< helpWebsites  
		<< "Std_TipOfTheDay"
		<< "Separator" 
		<< "Test_Test" 
		<< "Separator" 
		<< "Std_About"
		<< "Std_AboutQt" 
		<< "Separator" 
		<< "Std_WhatsThis" ;

	return menuBar;
}

ToolBarItem* CompleteWorkbench::setupToolBars() const
{
	//ToolBarItem* root = StdWorkbench::setupToolBars();
	//CommandManager &mgr = Gui_Application::instance->commandManager();
	ToolBarItem* root = new ToolBarItem;
    
	// File
	ToolBarItem* file = new ToolBarItem( root );

	file->setCommand("File");
	*file << "Std_New" 
		<< "Std_Open" 
		<< "Std_Save" 
		<< "Std_Print" 
		<< "Separator" 
		<< "Std_Cut"
		<< "Std_Copy" 
		<< "Std_Paste" 
		<< "Separator" 
		<< "Std_Undo" 
		<< "Std_Redo" 
		<< "Separator"
		<< "Std_Refresh" 
		<< "Separator" 
		//<< "Std_Workbench" 
		<< "Std_WhatsThis";

	// Macro
	ToolBarItem* macro = new ToolBarItem( root );
	macro->setCommand("Macro");
	*macro << "Std_DlgMacroRecord" << "Std_MacroStopRecord" << "Std_DlgMacroExecute"
		<< "Std_DlgMacroExecuteDirect";

	// View
	ToolBarItem* view = new ToolBarItem( root );
	view->setCommand("View");
	*view << "Std_ViewFitAll" << "Separator" << "Std_ViewAxo" << "Separator" << "Std_ViewFront" 
		<< "Std_ViewRight" << "Std_ViewTop" << "Separator" << "Std_ViewRear" << "Std_ViewLeft" 
		<< "Std_ViewBottom";

	// Part Design
	ToolBarItem* part_design = new ToolBarItem( root );
	part_design->setCommand("Part design");
	*part_design
		<< "Part_Box"
		<< "Part_Cylinder"
		<< "Part_Sphere"
		<< "Part_Cone"
		<< "Part_Torus"
		//<< "Part_Primitives"
		<< "Separator"
		<< "Part_Boolean"
		<< "Part_Cut" 
		<< "Part_Fuse" 
		<< "Part_Common" 
		<< "Part_Section"
		<< "Separator"
		<< "Part_Extrude"
		<< "Part_Revolve"
		<< "Part_Mirror"
		<< "Part_Fillet"
		<< "PartDesign_Chamfer"
		;

	// Sketch based

#   ifdef COMPLETE_SHOW_SKETCHER
	if (mgr.getCommandByName("Sketcher_NewSketch")) {
		Gui::ToolBarItem* sketch_based = new Gui::ToolBarItem( root );
		sketch_based->setCommand("Sketch based");
		*sketch_based 
			<< "Sketcher_NewSketch"
			<< "Separator"
			<< "PartDesign_Pad"
			<< "PartDesign_Fillet"
			;
	}
#   endif 

	// Drawing
	ToolBarItem* drawing = new ToolBarItem( root );
	drawing->setCommand("Drawings");
	*drawing << "Drawing_Open" 
		<< "Separator" 
		<< "Drawing_NewA3Landscape"  
		<< "Drawing_NewView" 
		<< "Drawing_ExportPage" ;

	// Raytracing
	ToolBarItem* raytracing = new ToolBarItem( root );
	raytracing->setCommand("Raytracing");
	*raytracing << "Raytracing_WriteView" 
		<< "Raytracing_WriteCamera" 
		<< "Raytracing_WritePart";

	// Drafting ****************************************************************************************************
//#   ifdef COMPLETE_USE_DRAFTING
//	if (mgr.getCommandByName("Draft_Line")) {
		ToolBarItem* Drafting = new ToolBarItem( root );
		Drafting->setCommand("Drafting");
		*Drafting
			<< "Draft_Line"
			<< "Draft_Wire"
			<< "Draft_Circle"
			<< "Draft_Arc"
			<< "Draft_Rectangle"
			<< "Draft_Polygon"
			<< "Draft_BSpline"
			<< "Draft_Text"
			<< "Draft_Dimension"
			<< "Separator" 
			<< "Draft_Move" 
			<< "Draft_Rotate" 
			<< "Draft_Offset" 
			<< "Draft_Trimex" 
			<< "Draft_Upgrade" 
			<< "Draft_Downgrade" 
			<< "Draft_Scale"
			<< "Draft_Edit"
			<< "Draft_Drawing"
			<< "Draft_WireToBSpline"
			<< "Draft_AddPoint";
			//<< "RenderView";

//	}
//#   endif

	return root;
}

ToolBarItem* CompleteWorkbench::setupCommandBars() const
{
	ToolBarItem* root = new ToolBarItem;
	return root;
}

void CompleteWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
{
	if (strcmp(recipient,"View") == 0)
	{
		MenuItem* StdViews = new MenuItem();
		StdViews->setCommand( "Standard views" );

		*StdViews << "Std_ViewAxo" << "Separator" << "Std_ViewFront" << "Std_ViewTop" << "Std_ViewRight"
			<< "Std_ViewRear" << "Std_ViewBottom" << "Std_ViewLeft";

		*item << "Std_ViewFitAll" << "Std_ViewFitSelection" << StdViews
			<< "Separator" << "Std_ViewDockUndockFullscreen";
	}

}
DockWindowItems* CompleteWorkbench::setupDockWindow() const
{
	DockWindowItems* root = StdWorkbench::setupDockWindow();
	root->setVisibility(false); // hide all dock windows by default
	root->setVisibility("Std_CombiView",true); // except of the combi view
	return root;
}

TYPESYSTEM_SOURCE(TestWorkBench,StdWorkbench)
TestWorkBench::TestWorkBench()
:StdWorkbench()
{

}
TestWorkBench::~TestWorkBench()
{

}

MenuItem* TestWorkBench::setupMenuBar()const
{
    return NULL;
}
ToolBarItem* TestWorkBench::setupToolBars()const
{
    return NULL;
}
ToolBarItem* TestWorkBench::setupCommandBars()const
{
    return NULL;
}


TYPESYSTEM_SOURCE(StartWorkbench, StdWorkbench)

StartWorkbench::StartWorkbench()
{
}

StartWorkbench::~StartWorkbench()
{
}

void StartWorkbench::activated()
{
// 	try {
// 		Gui::Command::doCommand(Gui::Command::Gui,"import WebGui");
// 		Gui::Command::doCommand(Gui::Command::Gui,"from StartPage import StartPage");
// #if defined(FC_OS_WIN32)
// 		Gui::Command::doCommand(Gui::Command::Gui,"WebGui.openBrowserHTML"
// 			"(StartPage.handle(),App.getResourceDir() + 'Mod/Start/StartPage/','Start page')");
// #else
// 		Gui::Command::doCommand(Gui::Command::Gui,"WebGui.openBrowserHTML"
// 			"(StartPage.handle(),'file://' + App.getResourceDir() + 'Mod/Start/StartPage/','Start page')");
// #endif
// 	}
// 	catch (const Base::Exception& e) {
// 		Base::Console().Error("%s\n", e.what());
// 	}
}

void StartWorkbench::setupContextMenu(const char* recipient,MenuItem* item) const
{

}

MenuItem* StartWorkbench::setupMenuBar() const
{
	return StdWorkbench::setupMenuBar();
}

ToolBarItem* StartWorkbench::setupToolBars() const
{
	ToolBarItem* root = StdWorkbench::setupToolBars();

	// web navigation toolbar
// 	ToolBarItem* navigation = new ToolBarItem(root);
// 	navigation->setCommand("Navigation");
// 	*navigation << "Web_OpenWebsite" 
// 		<< "Separator" 
// 		<< "Web_BrowserBack" 
// 		<< "Web_BrowserNext" 
// 		<< "Web_BrowserRefresh"
// 		<< "Web_BrowserStop"
// 		<< "Separator"
// 		<< "Web_BrowserZoomIn"
// 		<< "Web_BrowserZoomOut";

	return root;

}

ToolBarItem* StartWorkbench::setupCommandBars() const
{
	ToolBarItem* root = new ToolBarItem;
	return root;
}

DockWindowItems* StartWorkbench::setupDockWindows() const
{
	DockWindowItems* root = StdWorkbench::setupDockWindow();
	root->setVisibility(false); // hide all dock windows by default
	root->setVisibility("Std_CombiView",true); // except of the combi view
	return root;
}

/************************************************************************/
/*                                                                      */
/************************************************************************/
 

/// @namespace PartGui @class Workbench
TYPESYSTEM_SOURCE(PartWorkbench, StdWorkbench)

PartWorkbench::PartWorkbench()
{
}

PartWorkbench::~PartWorkbench()
{
}

MenuItem* PartWorkbench::setupMenuBar() const
{
	MenuItem* root = StdWorkbench::setupMenuBar();

  	MenuItem* item = root->findItem("&Windows");
  
  	MenuItem* prim = new MenuItem;
  	prim->setCommand("Primitives");
  	*prim << "Part_Box" << "Part_Cylinder" << "Part_Sphere"
  		<< "Part_Cone" << "Part_Torus";
  
  	MenuItem* part = new MenuItem;
  	root->insertItem(item, part);
  	part->setCommand("&Part");
  	*part << "Part_Import" << "Part_Export" << "Separator";
  	*part << prim << "Part_Primitives" << "Part_Builder" << "Separator"
  		<< "Part_ShapeFromMesh" << "Part_MakeSolid" << "Part_ReverseShape"
  		<< "Part_SimpleCopy" << "Part_RefineShape" << "Separator"
  		<< "Part_Boolean" << "Part_CrossSections" << "Part_Extrude"
  		<< "Part_Revolve" << "Part_Mirror" << "Part_Fillet" << "Part_Chamfer"
  		<< "Part_RuledSurface" << "Part_Loft" << "Part_Sweep";



	return root;
}

ToolBarItem* PartWorkbench::setupToolBars() const
{
	ToolBarItem* root = StdWorkbench::setupToolBars();

  	ToolBarItem* solids = new ToolBarItem(root);
  	solids->setCommand("Solids");
  	*solids << "macro-record" << "macro-stop" << "macro-execute";// << "Part_Cone"
//  		<< "Part_Torus" << "Part_Primitives" << "Part_Builder";
//  
//  	ToolBarItem* tool = new ToolBarItem(root);
//  	tool->setCommand("Part tools");
//  	*tool << "Part_Extrude" << "Part_Revolve" << "Part_Mirror" << "Part_Fillet"
//  		<< "Part_Chamfer" << "Part_RuledSurface" << "Part_Loft" << "Part_Sweep";
//  
//  	ToolBarItem* boolop = new ToolBarItem(root);
//  	boolop->setCommand("Boolean");
//  	*boolop << "Part_Boolean" << "Part_Cut" << "Part_Fuse" << "Part_Common"
//  		<< "Part_Section" << "Part_CrossSections";

	ToolBarItem* Drafting = new ToolBarItem( root );
	Drafting->setCommand("Drafting");
	*Drafting
 		<< "Draft_Line"
// 		<< "Draft_Wire"
 		<< "Draft_Circle"
// 		<< "Draft_Arc"
// 		<< "Draft_Rectangle"
// 		<< "Draft_Polygon"
// 		<< "Draft_BSpline"
// 		<< "Draft_Text"
// 		<< "Draft_Dimension"
// 		<< "Separator" 
		<< "Draft_Move" 
		<< "Draft_Rotate" 
// 		<< "Draft_Offset" 
// 		<< "Draft_Trimex" 
// 		<< "Draft_Upgrade" 
// 		<< "Draft_Downgrade" 
		<< "Draft_Scale"
// 		<< "Draft_Edit"
// 		<< "Draft_Drawing"
// 		<< "Draft_WireToBSpline"
// 		<< "Draft_AddPoint"
// 		<< "Draft_DelPoint";
        << "Separator" 
		 <<"FreeCamera"
	    <<"PathCamera";

	ToolBarItem* viewToolBar = new ToolBarItem(root);
	viewToolBar->setCommand("viewNums");
	*viewToolBar<<"RenderView"
		       <<"Std_ViewScreenShot"<<"Std_CalculateShadow"<<"Std_Statistics";

	return root;
}

ToolBarItem* PartWorkbench::setupCommandBars() const
{
	// Part tools
   ToolBarItem* root = new ToolBarItem;
	return root;
}




